package com.xijia.wuyouwallet.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.xijia.wuyouwallet.R;
import com.xijia.wuyouwallet.bean.BankListData;
import com.xijia.wuyouwallet.utils.StringUtils;

import java.util.List;

/**
 * Created by Administrator on 2017/8/25 0025.
 */

public class BankListAdapter extends BaseAdapter {

    private List<BankListData.DataBean.ListBean> list;
    private Context context;

    public BankListAdapter(List<BankListData.DataBean.ListBean> list,Context context){
        this.list = list;
        this.context = context;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder = null;
        if (view==null){
            view = LayoutInflater.from(context).inflate(R.layout.item_bank,null);
            holder = new ViewHolder();
            holder.itemBank_logon = (ImageView) view.findViewById(R.id.itemBank_logon);
            holder.itemBank_name = (TextView) view.findViewById(R.id.itemBank_name);
            holder.itemBank_type = (TextView) view.findViewById(R.id.itemBank_type);
            holder.itemBank_num = (TextView) view.findViewById(R.id.itemBank_num);
            view.setTag(holder);
        }else {
            holder = (ViewHolder) view.getTag();
        }
        Picasso.with(context).load(list.get(i).getBank_logo()).fit().into(holder.itemBank_logon);
        if (list.get(i).getCard_type().equals("0")){
            holder.itemBank_type.setText("信用卡");
        }else if (list.get(i).getCard_type().equals("1")){
            holder.itemBank_type.setText("储蓄卡");
        }
        //holder.itemBank_num.setText(list.get(i).getCard_number());
        holder.itemBank_num.setText("**** **** **** " + StringUtils.hintBankFourNum(list.get(i).getCard_number()));
        holder.itemBank_name.setText(list.get(i).getCard_bank());
        return view;
    }



    private class ViewHolder{
        ImageView itemBank_logon;
        TextView itemBank_name,itemBank_type,itemBank_num;
    }

}
